package com.example.teatea.dao;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;

public class FinishOrder {
    public void finishOrder(int num){
        int menu = 0;
        Connection connection = null;;
        Properties properties = new Properties();
        PreparedStatement presta = null;
        ResultSet resultSet = null;
        try {
            properties.load(new FileInputStream("src\\main\\resources\\com\\example\\teatea\\sql.properties"));
            String user = properties.getProperty("user");
            String password = properties.getProperty("password");
            String Driver = properties.getProperty("Driver");
            String url = properties.getProperty("url");
            Class.forName(Driver);
            String sql1 = "select rMenu from seat where rId = " + num;
            connection = DriverManager.getConnection(url,user,password);
            presta = connection.prepareStatement(sql1);
            resultSet = presta.executeQuery();
            if(resultSet.next()){
                menu = resultSet.getInt("rMenu");
            }
            String sql2 = "update menu set mType = 1 where mId = " + menu;
            String sql3 = "update seat set rState = 0,rMenu = 0 where rId = " + num;
            presta = connection.prepareStatement(sql2);
            presta.executeUpdate();
            presta = connection.prepareStatement(sql3);
            presta.executeUpdate();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
